package com.cuijq.ms.chaindesign.v3;

import java.util.ArrayList;
import java.util.List;

/**
 * @author by CuiJQ
 * @Classname HandlerChain
 * @Description HandlerChain Description
 * @Date 2021/5/29 10:19
 */
public class HandlerChain {

  private List<IHandler> handlers = new ArrayList<>();

  public void addHandler(IHandler handler) {
    this.handlers.add(handler);
  }

  public void handle() {
    for (IHandler handler : handlers) {
      boolean handled = handler.handle();
      if (handled) {
        break;
      }
    }
  }
}
